package com.feizhi.inventory.fragment.Inventorydetails;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.recyclerview.widget.RecyclerView;

import com.feizhi.inventory.database.TaskDetails;
import com.feizhi.inventory.databinding.ItemInventoryDetailsWinBinding;

import java.util.List;

/**
 *  盘点详情中recycler的适配器
 * */
public class InventoryProfitAdapter extends RecyclerView.Adapter<InventoryProfitAdapter.InventoryDetailsViewHolder> {

    private List<TaskDetails> data;
    private OnClickListener onClickListener;

    public InventoryProfitAdapter(List<TaskDetails> data) {
        this.data = data;
    }

    @Override
    public InventoryDetailsViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ItemInventoryDetailsWinBinding mBinding = ItemInventoryDetailsWinBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
        return new InventoryDetailsViewHolder(mBinding);
    }

    @Override
    public void onBindViewHolder(InventoryDetailsViewHolder holder, int position) {
        holder.mBinding.name.setText(data.get(position).getName());
        holder.mBinding.numberText.setText(data.get(position).getEpcID());
        holder.mBinding.date.setText(data.get(position).getId());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onClickListener.ItemOnClickListener(position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return data == null? 0 : data.size();
    }

    public void setData(List<TaskDetails> data) {
        this.data = data;
        notifyDataSetChanged();
    }
    public class InventoryDetailsViewHolder extends RecyclerView.ViewHolder {

        private ItemInventoryDetailsWinBinding mBinding;

        public InventoryDetailsViewHolder(ItemInventoryDetailsWinBinding mBinding) {
            super(mBinding.getRoot());
            this.mBinding = mBinding;

        }
    }

    public void setItemOnClickListener(OnClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }

    public interface OnClickListener {
        void ItemOnClickListener(int position);
    }
}
